package br.megareleased.rss;

import java.util.HashSet;
import java.util.Set;

import org.appwork.utils.event.Eventsender;

class RSSControllerBroadcaster extends Eventsender<RSSControllerListener, RSSControllerEvent> {

    @Override
    protected void fireEvent(final RSSControllerListener listener, final RSSControllerEvent event) {
        listener.onRSSControllerEvent(event);
    }
}

public class RSSController implements RSSControllerListener, RSSControllerInterface {

    private transient RSSControllerBroadcaster broadcaster    = new RSSControllerBroadcaster();
	private Set<RSS> rssList = new HashSet<RSS>();
    private static RSSController INSTANCE = new RSSController();

    public static RSSController getInstance() {
        return INSTANCE;
    }

    private RSSController() {
        broadcaster.addListener(this);
    }

    public void addListener(final RSSControllerListener l) {
        broadcaster.addListener(l);
    }

    public void removeListener(final RSSControllerListener l) {
        broadcaster.removeListener(l);
    }

	@Override
	public void addRSS(RSS... r) {
		for (RSS rss : r) {
			this.rssList.add(rss);
			broadcaster.fireEvent(new RSSControllerEvent(this, RSSControllerEvent.ADD_RSS, rss));
		}
	}

	@Override
	public void removeRSS(RSS... r) {
	}

	@SuppressWarnings("deprecation")
	@Override
	public void onRSSControllerEvent(RSSControllerEvent event) {
	    switch (event.getEventID()) {
        case RSSControllerEvent.ADD_RSS:
        case RSSControllerEvent.REMOVE_RSS:
        case RSSControllerEvent.REFRESH_DATA:
        }
	}

	public Set<RSS> getRSS() {
		return rssList;
	}
}
